<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>角色仓库权限设置</title>
    <script type="text/javascript">

      var roleWarehouseDS;

      //处理权限锁定
      function lockRoleWarehouseFn(id){
        Ext.Ajax.request({
          url : '/privilege/roleWarehouseLock',
          success : function (result, request) {
            roleWarehouseDS.reload();
          },
          failure : function (result, request){
            Ext.MessageBox.show({
              title: '消息',
              msg: "通讯失败，请从新操作",
              buttons: Ext.MessageBox.OK,
              icon: Ext.MessageBox.WARNING
            });
          },
          method : 'GET',
          params : {
            id : id
          }
        });
      }

      //处理角色
      function lockRoleWarehouseFn(id){
        Ext.Ajax.request({
          url : '/admin/roleWarehouseLock',
          success : function (result, request) {
            roleWarehouseDS.reload();
          },
          failure : function (result, request){
            Ext.MessageBox.show({
              title: '消息',
              msg: "通讯失败，请从新操作",
              buttons: Ext.MessageBox.OK,
              icon: Ext.MessageBox.WARNING
            });
          },
          method : 'GET',
          params : {
            id : id
          }
        });
      }

      Ext.onReady(function(){
        //-----------------角色Grid----------------------------
        roleWarehouseDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/admin/getRoleWarehouse?role_id=<%=params[:role_id]%>'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'name'
            },{
              name: 'created_at'
            },{
              name: 'is_locked'
            }])
        });

        var roleWarehouseCM = new Ext.grid.ColumnModel({defaults: {
            sortable: true,
            menuDisabled: false
          },columns:[new Ext.grid.RowNumberer(),
            {
              header: '是否锁定',
              dataIndex: 'is_locked',
              renderer: renderRoleWarehouseIsLucked,
              width: 60
            },{
              header: '仓库名称',
              dataIndex: 'name',
              width: 190
            }
          ]});

        //锁定角色
        function renderRoleWarehouseIsLucked(value, cellmeta, record, rowIndex, columnIndex, store){
          if (record.get("is_locked")=="1"){
            return "<a style=cursor:pointer onclick=lockRoleWarehouseFn(" + store.getAt(rowIndex).get('id')+")><font color=red>锁定</font></a>";
          }else{
            return "<a style=cursor:pointer onclick=lockRoleWarehouseFn(" + store.getAt(rowIndex).get('id')+")><font color=green>未锁定</font></a>";
          }
        }

        var roleGrid = new Ext.grid.GridPanel({
          title:'角色仓库列表',
          store: roleWarehouseDS,
          cm: roleWarehouseCM,
          width: 325,
          height: 265,
          frame: true,
          loadMask: true
        });
        roleWarehouseDS.load();
        
        roleGrid.render("role_warehouse_workbanch");
      })
    </script>
  </head>
  <body>
    <div id="role_warehouse_workbanch"></div>
  </body>
</html>
